package com.supermap.application.service;

import com.supermap.application.dao.MacroDataDao;
import com.supermap.application.entity.TMacroData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 宏观数据业务层
 */
@Service
public class MacroDataService {

    @Autowired
    MacroDataDao macroDataDao;

    /**
     * 获取看板经济数据
     * @return map
     */
    public Map getAreaGDP(String year){
        Map map = new HashMap();
        //获取各个指标数据
        String count1 = macroDataDao.computeGDP(year);
        String count2 = macroDataDao.computeFixedAssets(year);
        String count3 = macroDataDao.computeSell(year);
        String count4 = macroDataDao.computeExit(year);

        String [] arr_name = new String[4];
        arr_name[0] = "地区生产总值";
        arr_name[1] = "固定资产投资总额";
        arr_name[2] = "社会消费品零售总额";
        arr_name[3] = "进出口总额";

        String [] arr_value = new String[4];
        arr_value[0] = count1;
        arr_value[1] = count2;
        arr_value[2] = count3;
        arr_value[3] = count4;

        List list = macroDataDao.computeExtremeReport(year);

        map.put("name",arr_name);
        map.put("data",arr_value);
        map.put("report",list);
        map.put("year",year);
        map.put("unit","亿元");
        return map;
    }

    /**
     * 获取规模以上工业月份数据
     * @param year 年度
     * @return list
     */
    public Map getAboveIndustry(String year){
        Map map = new HashMap();
        List list = macroDataDao.getAboveIndustry(year);
        TMacroData macroData = macroDataDao.getAllUnit();
        map.put("name","规模以上工业值");
        map.put("data",list);
        map.put("unit",macroData.getR00004());
        return map;
    }


    /**
     * 获取产业占比数据
     * @param year 年份
     * @return map
     */
    public Map getIndustryProportion(String year){
        Map map = new HashMap();
        List<TMacroData> list = macroDataDao.getMacroDataList(year);
        TMacroData macroDataEntry = macroDataDao.getAllUnit();
        double c = 0,f = 0,s = 0,t = 0;
        for (TMacroData macroData : list) {
            if (macroData.getD00001() != null) {
                c += Double.valueOf(macroData.getD00001());
            }
            if (macroData.getD00002() != null) {
                f += Double.valueOf(macroData.getD00002());
            }
            if (macroData.getD00003() != null) {
                s += Double.valueOf(macroData.getD00003());
            }
            if (macroData.getD00004() != null) {
                t += Double.valueOf(macroData.getD00004());
            }
        }

        String [] arr_name = new String[3];
        arr_name[0] = "第一产业";
        arr_name[1] = "第二产业";
        arr_name[2] = "第三产业";

        double [] arr_value = new double[3];
        arr_value[0] = f;
        arr_value[1] = s;
        arr_value[2] = t;

        map.put("name",arr_name);
        map.put("data",arr_value);
        map.put("unit",macroDataEntry.getD00001());
        return map;
    }


    /**
     * 获取房产占比固投数据
     * @param year 年份
     * @return map
     */
    public Map getRealtyProportion(String year){
        Map map = new HashMap();
        List<TMacroData> list = macroDataDao.getMacroDataList(year);
        TMacroData macroDataEntry = macroDataDao.getAllUnit();
        double a = 0,b = 0;
        for (TMacroData macroData : list) {
            if (macroData.getG00001() != null) {
                a += Double.valueOf(macroData.getD00001());
            }
            if (macroData.getG00003() != null) {
                b += Double.valueOf(macroData.getD00003());
            }
        }

        String [] arr_name = new String[2];
        arr_name[0] = "固定投资总额";
        arr_name[1] = "房地产投资";

        double [] arr_value = new double[2];
        arr_value[0] = a;
        arr_value[1] = b;

        map.put("name",arr_name);
        map.put("data",arr_value);
        map.put("unit",macroDataEntry.getG00001());
        return map;
    }



    /**
     * 获取房产开发月份数据
     * @param year 年度
     * @return list
     */
    public Map getRealty(String year){
        Map map = new HashMap();
        List list = macroDataDao.getRealty(year);
        TMacroData macroData = macroDataDao.getAllUnit();
        map.put("name","房地产开发投资额");
        map.put("data",list);
        map.put("unit",macroData.getG00003());
        return map;
    }


    /**
     * 获取税收总额
     * @param year 年度
     * @return list
     */
    public Map getRatepay(String year){
        Map map = new HashMap();
        List list = macroDataDao.getRatepay(year);
        TMacroData macroData = macroDataDao.getAllUnit();
        map.put("name","税收总额");
        map.put("data",list);
        map.put("unit",macroData.getC00003());
        return map;
    }


    /**
     * 获取年度人口月份数据
     * @return list
     */
    public Map getPopulation(){
        Map map = new HashMap();
        List list = macroDataDao.getPopulation();
        TMacroData macroData = macroDataDao.getAllUnit();
        map.put("name","年末常住人口");
        map.put("data",list);
        map.put("unit",macroData.getZ00003());
        return map;
    }

}
